<template>
  <div class="box">
    <div class="head-search">
      <search :formInline="searchData" @onSubmit="onSearch">
        <el-form-item>
          <el-input placeholder="请输入内容" clearable v-model="val" size="small" class="input-with-select">
            <el-select v-model="select" clearable slot="prepend" placeholder="请选择">
              <el-option label="餐厅名" value="1"></el-option>
              <el-option label="订单号" value="2"></el-option>
              <el-option label="用户电话" value="3"></el-option>
            </el-select>
          </el-input>
        </el-form-item>
      </search>
    </div>
    <section class="fun-btn">
      <el-button type="primary" size="small"
                 @click="handleAddEdit('add')"
                 icon="el-icon-circle-plus-outline">新增
      </el-button>
      <el-button type="danger" plain @click="handleDel" size="small">删除</el-button>

    </section>
    <div class="list-box">
      <el-table
        :data="tableData"
        row-key="id"
        border
        v-loading="tableLoading"
        height="calc(100vh - 240px)"
        default-expand-all
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
        <el-table-column
          fixed="left"
          type="selection"
          align="center"
          width="60">
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="date"
          label="类别"
          width="180">
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="name"
          label="描述"
          width="180">
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="address"
          label="期限">
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="address"
          label="排序">
        </el-table-column>
        <el-table-column
          fixed="right"
          align="center"
          label="操作"
          width="150">
          <template slot-scope="scope">
            <el-button type="text" @click="handleAddEdit('see', scope.row)">查看</el-button>
            <el-button type="text" @click="handleAddEdit('edit', scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!--<el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.pageNo"
        :page-sizes="[20, 40, 60, 80]"
        :page-size="page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total">
      </el-pagination>-->
    </div>

    <el-dialog :title="dialogTitle"
               :width="dialogWidth"
               top="5vh"
               :destroy-on-close="true"
               :close-on-click-modal="false"
               :close-on-press-escape="false"
               :visible.sync="dialogShow">
      <div class="import-content">
        <add-edit-see-period :type="type" @handleCancel="dialogShow=false"></add-edit-see-period>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Search from '../../../../components/search/search'
import AddEditSeePeriod from '../settingComponents/period/addEditSeePeriod'
import { getTermList } from '../../../../api/storagePeriod'

export default {
  name: 'StoragePeriod',
  components: { AddEditSeePeriod, Search },
  // 保管期限表
  data () {
    return {
      val: '', // 筛选
      select: '', // 筛选
      searchData: {
        user: ''
      },
      dialogTitle: '分类信息',
      dialogWidth: '600px',
      dialogShow: false,
      type: 'add',
      tableLoading: true,
      page: {
        pageNo: 1,
        pageSize: 20,
        total: 0
      },
      tableData: [{
        id: 1,
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        id: 2,
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄',
        children: [{
          id: 311,
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }, {
          id: 321,
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }]
      }, {
        id: 3,
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄',
        children: [{
          id: 31,
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }, {
          id: 32,
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }]
      }, {
        id: 4,
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄',
        children: [{
          id: 312,
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }, {
          id: 323,
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }]
      }]
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    async getList () {
      this.tableLoading = false
      const param = {
      }
      await getTermList(param).then(res => {
        console.log(res.data.data)
      })
      this.tableLoading = false
    },
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
    },
    onSearch (val) {
      // 搜索
      console.log(val)
    },
    handleAddEdit (type, row) {
      console.log(row)
      const title = {
        add: '新增',
        see: '查看',
        edit: '编辑'
      }
      this.dialogTitle = title[type]
      this.dialogShow = true
      this.type = type
      // dialogWidth: '600px',
    },
    handleDel () {
      // 删除
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .box {

  }
</style>
